package com.cby.springboot.demo.mapper;

import com.cby.springboot.demo.bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from user")
    List<User> getAllUsers();

    //通过用户名密码查询用户数据
    User getByUserNameAndPassword(User user);

    @Select("select * from user where user_name = #{userName,jdbcType=VARCHAR}")
    User getByUserName(String userName);

    @Insert("insert into user ( user_id, user_name, password, email, salt, phone)" +
            "values ( #{userId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}," +
            " #{password,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR})")
    int insert(User record);

    @Update(" update user" +
            "    set user_id = #{userId,jdbcType=VARCHAR},\n" +
            "      user_name = #{userName,jdbcType=VARCHAR},\n" +
            "      password = #{password,jdbcType=VARCHAR},\n" +
            "      phone = #{phone,jdbcType=VARCHAR},\n" +
            "      email = #{email,jdbcType=VARCHAR},\n" +
            "      email = #{phone,jdbcType=VARCHAR}\n" +
            "    where id = #{id,jdbcType=INTEGER}")
    int updateByPrimaryKey(User record);

    @Select("select * from user where user_name LIKE CONCAT('%',#{userName,jdbcType=VARCHAR},'%')")
    User getByName(@Param("userName") String userName);
}
